#!/usr/bin/env python
# $Id: type_list.py 18 2012-07-07 03:16:22Z benchline@gmail.com $

from page import page
import sys, time, urllib
import db

class add(page):

	def __init__(self):
		page.__init__(self)
		self.headingstr = "Category Administration"
		self.db1 = db.db()
		self.upcdb1 = db.upcdb()

	def render(self):
		self.logic()
		self.encoding()
		self.html()

	def logic(self):
		if request.has_key("cancel"):
			raise HTTP_REDIRECTION, "menu.py"

	def form(self):
		form = """
		<form name="add" method="GET" action="item_detail.py">
		<input type=submit name=cancel value="Menu">
		</form>
        <a href=add_types.py>Add Type</a>
		"""
		print form

	def show_detail(self):
		"""
		Show the detail
		"""
		print """<table border=1 cellpadding=3 cellspacing=0>
		<tr style='font-weight: bold;'>
			<td>Category</td>
			<td>Shelf Life</td>
			<td>Goal Amt</td>
			<td>Goal Unit</td>
		</tr>
		"""
		for line in self.db1.get_type_list_detail():
			print "<tr><td><a href=add_types.py?id=%s>%s</a></td><td>%s</td><td>%s</td><td>%s</td></tr>" % line
		print "</table>"

	def message(self):
		if request.has_key("m"):
			message = request["m"][0]
			if message:
				print message

	def body(self):
		self.start_body()
		self.heading()
		self.message()
		self.show_detail()
		self.form()
		self.footer()
		self.end_body()

class runner:
	def _test(self):
		add().render()

	def _doctest(self):
		import doctest
		doctest.testmod()

if __name__ == "__main__":
	r = runner()
	getattr(r, "_"+sys.argv[1])()
else:
	add().render()
